<?php
include('../../inc/global.inc');
include("../islogin.php");
$urls=$_SERVER['HTTP_REFERER'];
?>
<?php 
$id_del=$_POST["id_del"];
if($id_del!=""){ 
$del_num=count($id_del); 
for($i=0;$i<$del_num;$i++){ 

  $d_rs=@mysql_query("select * from buy where id='$id_del[$i]'");
  $d_row=@mysql_fetch_array($d_rs);
  if($d_row[catalog_id1]){
       $c_rs=@mysql_query("select * from catalog where id='$d_row[catalog_id1]'");
	   $c_row=@mysql_fetch_array($c_rs);
	   $b_num=$c_row[b_num]-1;
	   mysql_query("update catalog set b_num='$b_num' where id='$c_row[id]'");
  }
  if($d_row[catalog_id2]){
       $c_rs=@mysql_query("select * from catalog where id='$d_row[catalog_id2]'");
	   $c_row=@mysql_fetch_array($c_rs);
	   $b_num=$c_row[b_num]-1;
	   mysql_query("update catalog set b_num='$b_num' where id='$c_row[id]'");
  }  
 if($d_row[catalog_id3]){
       $c_rs=@mysql_query("select * from catalog where id='$d_row[catalog_id3]'");
	   $c_row=@mysql_fetch_array($c_rs);
	   $b_num=$c_row[b_num]-1;
	   mysql_query("update catalog set b_num='$b_num' where id='$c_row[id]'");
  } 
  mysql_query("delete from buy where id='$id_del[$i]'");

}

  echo "<script>location='".$urls."';</script>"; 
}else{ 
  echo "<script>alert('请选择您要删除项目');history.back();</script>";
} 
?> 
